#pragma strict
var leftScript : MatchingScript;
var rightScript : MatchingScript;
var upScript : MatchingScript;
var downScript : MatchingScript;
var objColor : Transform;
var leftColor : Transform;
var rightColor : Transform;
var downColor : Transform;
var upColor : Transform;

function Start() {
	//assign triggers to variables
	
	leftScript = transform.Find("leftTrigger").gameObject.GetComponent("MatchingScript");
	rightScript = transform.Find("rightTrigger").gameObject.GetComponent("MatchingScript");
	upScript = transform.Find("upTrigger").gameObject.GetComponent("MatchingScript");
	downScript = transform.Find("downTrigger").gameObject.GetComponent("MatchingScript");
	objColor = gameObject.collider.transform.Find("Color");
}



function Update () {
	//check for matches
	
	if (rigidbody.velocity.magnitude == 0){
	//ball is not moving
	
		gameObject.transform.Find("Movement").gameObject.tag = "Not Moving";
		
		
		if (gameObject.transform.position.z == 2661){
			gameObject.transform.Find("Column").gameObject.tag = "A";
		}
		else if (gameObject.transform.position.z == 2677){
			gameObject.transform.Find("Column").gameObject.tag = "B";
		}
		else if (gameObject.transform.position.z == 2693){
			gameObject.transform.Find("Column").gameObject.tag = "C";
		}
		else if (gameObject.transform.position.z == 2709){
			gameObject.transform.Find("Column").gameObject.tag = "D";
		}
		else if (gameObject.transform.position.z == 2725){
			gameObject.transform.Find("Column").gameObject.tag = "E";
		}
		else if (gameObject.transform.position.z == 2741){
			gameObject.transform.Find("Column").gameObject.tag = "F";
		}
		else if (gameObject.transform.position.z == 2757){
			gameObject.transform.Find("Column").gameObject.tag = "G";
		}
		else if (gameObject.transform.position.z == 2773){
			gameObject.transform.Find("Column").gameObject.tag = "H";
		}
		else {
			//shouldn't be here
		}
		
		
									
	}//end not moving
	
else {
	//ball is moving
	gameObject.transform.Find("Movement").gameObject.tag = "Moving";
	}
}


function DestroyCheck(){
	
		
		if (leftScript.isMatch && rightScript.isMatch){
		//Debug.Log("horiz match");
			//leftColor = leftScript.otherBall.gameObject.collider.transform.Find("Color");
			//rightColor = rightScript.otherBall.gameObject.collider.transform.Find("Color");
		 
		 
		  	//if ((objColor.tag == "Moved" || rightColor.tag == "Moved" || leftColor.tag == "Moved")) {
				//Debug.Log("horizontal match");
				gameObject.tag = "Destroy";
				//objColor.tag = "Moved";
				leftScript.otherBall.gameObject.tag = "Destroy";
				//leftColor.tag = "Moved";
				rightScript.otherBall.gameObject.tag = "Destroy";
				//rightColor.tag = "Moved";
			//}
		}
		
		if (upScript.isMatch && downScript.isMatch){
		//Debug.Log("vert match");
			//downColor = downScript.otherBall.gameObject.collider.transform.Find("Color");
			//upColor = upScript.otherBall.gameObject.collider.transform.Find("Color");
		  //	if((objColor.tag == "Moved" || downColor.tag == "Moved" || upColor.tag == "Moved")) {
			//	Debug.Log("vertical match");
				gameObject.tag = "Destroy";
			//	objColor.tag = "Moved";
				upScript.otherBall.gameObject.tag = "Destroy";
			//	upColor.tag = "Moved";
			downScript.otherBall.gameObject.tag = "Destroy";
			//	downColor.tag = "Moved";
			//}
		}	


}